import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"
import { useGlobSetting } from "/@/hooks/setting"
const globSetting = useGlobSetting()

export const pageConfig = (params) => {
  return defHttp.get({ url: "/infra-service/config/pageConfig", params })
}

export const getConfigByKey = (configKey: string) => {
  return defHttp.get({ url: "/infra-service/config/getConfigByKey", params: { configKey } })
}

export const saveOrUpdate = (params, isUpdate) => {
  const url = isUpdate ? "/infra-service/config/updateConfig" : "/infra-service/config/saveConfig"
  return defHttp.post({ url: url, params })
}

export const updateStatus = (params) => {
  return defHttp.post({ url: "/infra-service/config/updateStatus", params }, { joinParamsToUrl: true })
}


export const deleteConfig = (params, handleSuccess) => {
  return defHttp.delete({ url: "/infra-service/config/deleteConfig", data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const batchDeleteConfig = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: "/infra-service/config/batchDeleteConfig", data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}
